package com.qf.shiro2202day02.user.service.impl;

import com.qf.shiro2202day02.user.entity.User;
import com.qf.shiro2202day02.user.dao.UserDao;
import com.qf.shiro2202day02.user.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.shiro2202day02.user.utils.SaltUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yh
 * @since 2022-10-25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void regist(User user) {
        String salt = SaltUtils.getSalt(8);
        Md5Hash md5Hash = new Md5Hash(user.getPassword(), salt, 1024);
        String shiroPassword = md5Hash.toHex();
        user.setSalt(salt);
        user.setPassword(shiroPassword);
        this.save(user);
    }
}
